package ch.fusun.baron.treasury;

import java.util.Map;

import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.data.DataUpdate;
import ch.fusun.baron.treasury.api.TreasuryService;

/**
 * Updates the {@link TreasuryService}
 */
public class TreasuryDataUpdate implements DataUpdate {

	@Inject
	private transient TreasuryService service;

	private Map<Object, Integer> moneyMap;

	/**
	 * Don't use
	 */
	public TreasuryDataUpdate() {
		// for injection
	}

	/**
	 * Constructor
	 * 
	 * @param moneyMap
	 *            The map from players to money
	 */
	public TreasuryDataUpdate(Map<Object, Integer> moneyMap) {
		this.moneyMap = moneyMap;
	}

	@Override
	public void update() {
		for (Object player : moneyMap.keySet()) {
			service.setMoney(player, moneyMap.get(player));
		}
	}
}
